package com.funo.logic.controller;

import cn.hutool.json.JSONUtil;
import com.funo.logic.generate.GenerateCodeService;
import com.funo.logic.model.LogicService;
import com.funo.logic.response.HandleResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("code")
public class CodeController {

    @Autowired
    private GenerateCodeService generateCodeService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("create")
    public HandleResult create(String id) {
        String key = "logicService:" + id;
        LogicService logicService = JSONUtil.toBean(stringRedisTemplate.opsForValue().get(key), LogicService.class);
        generateCodeService.generateJavaCode(logicService);
        return HandleResult.success();
    }
}
